package com.tianhui.consignortwofei.other;

import android.text.TextUtils;

import com.fgs.common.utils.CommonUtil;
import com.fgs.common.utils.LogUtil;
import com.fgs.common.utils.StringUtil;
import com.fgs.common.utils.ToastUtil;
import com.tianhui.consignortwofei.mvp.model.enty.GoodsInfo;
import com.tianhui.consignortwofei.mvp.model.enty.SourcePathInfo;

import java.math.BigDecimal;

/**
 * @author fgs
 * @date 2021/6/18
 * @description
 **/
public class DeliverGoodsDataProcess {

    public void processPlaceSelectPathInfo(GoodsInfo goodsInfo, SourcePathInfo pathInfo) {
        goodsInfo.placeprovince = pathInfo.placeprovince;
        goodsInfo.placecity = pathInfo.placecity;
        goodsInfo.placecounty = pathInfo.placecounty;
        goodsInfo.placecitycode = pathInfo.placecitycode;
        goodsInfo.placeParentCode = pathInfo.placeparentcode;
    }

    public void processDeliverySelectPathInfo(GoodsInfo goodsInfo, SourcePathInfo pathInfo) {
        goodsInfo.deliverprovince = pathInfo.placeprovince;
        goodsInfo.delivercity = pathInfo.placecity;
        goodsInfo.delivercounty = pathInfo.placecounty;
        goodsInfo.delivercitycode = pathInfo.placecitycode;
        goodsInfo.deliverParentCode = pathInfo.placeparentcode;
        LogUtil.print("goodsInfo.deliverParentCode", goodsInfo.deliverParentCode);
    }

    public void processDestinationSelectPathInfo(GoodsInfo goodsInfo, SourcePathInfo pathInfo) {
        goodsInfo.destinationprovince = pathInfo.placeprovince;
        goodsInfo.destinationcity = pathInfo.placecity;
        goodsInfo.destinationcounty = pathInfo.placecounty;
        goodsInfo.destinationcitycode = pathInfo.placecitycode;
        goodsInfo.destinationParentCode = pathInfo.placeparentcode;
    }

    public boolean checkDeliveryInfoPassOrNot(GoodsInfo goodsInfo) {

        if (TextUtils.isEmpty(goodsInfo.deliverprovince)) {
            showToast("装货地不能为空");
            return false;
        }
        if (TextUtils.isEmpty(goodsInfo.deliverParentCode)) {
            showToast("装货地必须精确到市级以上");
            return false;
        }

//        if (TextUtils.isEmpty(goodsInfo.delivercounty)) {
//            showToast("装货地必须精确到区");
//            return false;
//        }

        if (TextUtils.isEmpty(goodsInfo.delivercitycode)) {
            showToast("请在装货地列表中选择地区");
            return false;
        }

        if (TextUtils.isEmpty(goodsInfo.deliverusername)) {
            showToast("装货人不能为空");
            return false;
        }
//        if (TextUtils.isEmpty(goodsInfo.delivertel)) {
//            showToast("装货人联系电话不能为空");
//            return false;
//        }
        return true;
    }

    public boolean checkDestinationInfoPassOrNot(GoodsInfo goodsInfo) {
        if (TextUtils.isEmpty(goodsInfo.destinationprovince)) {
            showToast("目的地不能为空");
            return false;
        }

        if (TextUtils.isEmpty(goodsInfo.destinationParentCode)) {
            showToast("目的地必须精确到市级以上");
            return false;
        }

//        if (TextUtils.isEmpty(goodsInfo.destinationcounty)) {
//            showToast("目的地必须精确到区");
//            return false;
//        }

        if (TextUtils.isEmpty(goodsInfo.destinationcitycode)) {
            showToast("请在目的地列表中选择地区");
            return false;
        }


        if (TextUtils.isEmpty(goodsInfo.destinationusername)) {
            showToast("收货人不能为空");
            return false;
        }
//        if (TextUtils.isEmpty(goodsInfo.destinationtel)) {
//            showToast("收货人联系电话不能为空");
//            return false;
//        }


        return true;
    }

    public boolean checkGoodsDetachWeightIsRight(GoodsInfo goodsInfo, String detachWeight) {
        if (TextUtils.isEmpty(goodsInfo.weight)) {
            showToast("请填写货物重量");
            return false;
        }
        if (!TextUtils.isEmpty(goodsInfo.detachable) && goodsInfo.detachable.equals("1")) {
            if (TextUtils.isEmpty(detachWeight)) {
                showToast("请填写拆单重量");
                return false;
            } else {

                if (Double.parseDouble(detachWeight) == 0) {
                    showToast("拆单重量不能为0");
                    return false;
                }
                if (StringUtil.compareTwoString(detachWeight, goodsInfo.weight) == 1) {
                    showToast("拆单重量不能大于发单重量");
                    return false;
                }
                if (StringUtil.compareTwoString(detachWeight, goodsInfo.weight) == 0) {
                    showToast("拆单重量不能等于发单重量");
                    return false;
                }
                goodsInfo.detachweight = detachWeight;
            }
        }
        return true;
    }

    public boolean checkLiteDeliverGoodsInquiryState(GoodsInfo goodsInfo) {
        if (!TextUtils.isEmpty(goodsInfo.ishide) && goodsInfo.ishide.equals("1")) {
            if (TextUtils.isEmpty(goodsInfo.facetel)) {
                showToast("请填写询价电话");
                return false;
            }
            goodsInfo.baseprice = "0";
            goodsInfo.bigprice = "0";
            goodsInfo.totalprice = "0";
        } else {
            goodsInfo.facetel = "";
            return checkGoodsPriceIsRight(goodsInfo);

        }
        return true;
    }


    public boolean checkGoodsPriceIsRight(GoodsInfo goodsInfo) {
        if (TextUtils.isEmpty(goodsInfo.baseprice)) {
            showToast("请填写运费单价");
            return false;
        }
        if (TextUtils.isEmpty(goodsInfo.bigprice)) {
            showToast("请填写最高接受价");
            return false;
        }
        if (StringUtil.compareTwoString(goodsInfo.baseprice, goodsInfo.bigprice) == 1) {
            showToast("最高接受价不能小于运费单价");
            return false;
        }
        return true;
    }

    public boolean checkLoadingAndUnLoadingTimeIsRight(GoodsInfo goodsInfo) {

        if (TextUtils.isEmpty(goodsInfo.lendtime)) {
            showToast("请选择装货截止时间");
            return false;
        }

        if (TextUtils.isEmpty(goodsInfo.unloadearlhours)) {
            showToast("请输入预计卸车时间");
            return false;
        }
        return true;
    }

    public String getTotalPrice(String price, String goodsWeight) {

        //数据失精处理

        price = TextUtils.isEmpty(price) ? "0" : price;
        goodsWeight = TextUtils.isEmpty(goodsWeight) ? "0" : goodsWeight;

        String totalPrice = new BigDecimal(price).multiply(new BigDecimal(goodsWeight)).toString();//两个数字相乘（加减乘除的单词就是方法）

        return CommonUtil.keepTwoDecimal(totalPrice);
    }

    private void showToast(String message) {
        ToastUtil.showShortToast(message);
    }





    public boolean checkDeliveryInfoPassOrNotFindCar(GoodsInfo goodsInfo) {

        if (TextUtils.isEmpty(goodsInfo.deliverprovince)) {
            showToast("装货地不能为空");
            return false;
        }
        if (TextUtils.isEmpty(goodsInfo.deliverParentCode)) {
            showToast("装货地必须精确到市级以上");
            return false;
        }

        if (TextUtils.isEmpty(goodsInfo.delivercounty)) {
            showToast("装货地必须精确到区");
            return false;
        }

        if (TextUtils.isEmpty(goodsInfo.delivercitycode)) {
            showToast("请在装货地列表中选择地区");
            return false;
        }

//        if (TextUtils.isEmpty(goodsInfo.deliverusername)) {
//            showToast("装货人不能为空");
//            return false;
//        }
//        if (TextUtils.isEmpty(goodsInfo.delivertel)) {
//            showToast("装货人联系电话不能为空");
//            return false;
//        }
        return true;
    }

    public boolean checkDestinationInfoPassOrNotFindCar(GoodsInfo goodsInfo) {
        if (TextUtils.isEmpty(goodsInfo.destinationprovince)) {
            showToast("目的地不能为空");
            return false;
        }

        if (TextUtils.isEmpty(goodsInfo.destinationParentCode)) {
            showToast("目的地必须精确到市级以上");
            return false;
        }

        if (TextUtils.isEmpty(goodsInfo.destinationcounty)) {
            showToast("目的地必须精确到区");
            return false;
        }

        if (TextUtils.isEmpty(goodsInfo.destinationcitycode)) {
            showToast("请在目的地列表中选择地区");
            return false;
        }


//        if (TextUtils.isEmpty(goodsInfo.destinationusername)) {
//            showToast("收货人不能为空");
//            return false;
//        }
//        if (TextUtils.isEmpty(goodsInfo.destinationtel)) {
//            showToast("收货人联系电话不能为空");
//            return false;
//        }


        return true;
    }



}
